package gitee.derumin.lifeissohard.mixin;

import com.mojang.authlib.GameProfile;
import gitee.derumin.lifeissohard.tools.LishIdentifiers;
import gitee.derumin.lifeissohard.tools.LishNetworkPackets;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ServerPlayerEntity.class)
public abstract class ServerPlayerEntityMixin extends PlayerEntity {
    public ServerPlayerEntityMixin(World world, BlockPos pos, float yaw, GameProfile gameProfile) {
        super(world, pos, yaw, gameProfile);
    }

    @Inject(method = "playerTick" , at = @At(value = "TAIL"))
    private void changeHealthPacket(CallbackInfo ci){
        if (!this.world.isClient)ServerPlayNetworking.send((ServerPlayerEntity)((PlayerEntity)this), LishIdentifiers.Packets.S2CPackets.HUNGER_MANAGER_PACKET, LishNetworkPackets.createHungerManagerPacket(this.getHungerManager()));
    }
}
